/** * @file * Attaches behaviors for the Clientside Validation jQuery module. */ (function ($, Drupal, debounce, CKEDITOR) { /** * Attaches jQuery validate behavoir to forms. * * @type {Drupal~behavior} * * @prop {Drupal~behaviorAttach} attach * Attaches the outline behavior to the right context. */ Drupal.behaviors.cvJqueryValidateCKEditor = { attach: function (context) { if (typeof CKEDITOR === 'undefined') { return; } var ignore = ':hidden'; var not = []; for (var instance in CKEDITOR.instances) { if (CKEDITOR.instances.hasOwnProperty(instance)) { not.push('#' + instance); } } ignore += not.length ? ':not(' + not.join(', ') + ')' : ''; $('form').each(function () { var validator = $(this).data('validator'); if (!validator) { return; } validator.settings.ignore = ignore; validator.settings.errorPlacement = function(place, $element) { var id = $element.attr('id'); var afterElement = $element[0]; if (CKEDITOR.instances.hasOwnProperty(id)) { afterElement = CKEDITOR.instances[id].container.$; } place.insertAfter(afterElement); }; }); var updateText = function (instance) { return debounce(function (e) { instance.updateElement(); var event = $.extend(true, {}, e.data.$); delete event.target; delete event.explicitOriginalTarget; delete event.originalTarget; delete event.currentTarget; $(instance.element.$).trigger(new $.Event(e.name, event)); }, 250); }; CKEDITOR.on('instanceReady', function () { for (var instance in CKEDITOR.instances) { if (CKEDITOR.instances.hasOwnProperty(instance)) { CKEDITOR.instances[instance].document.on("keyup", updateText(CKEDITOR.instances[instance])); CKEDITOR.instances[instance].document.on("paste", updateText(CKEDITOR.instances[instance])); CKEDITOR.instances[instance].document.on("keypress", updateText(CKEDITOR.instances[instance])); CKEDITOR.instances[instance].document.on("blur", updateText(CKEDITOR.instances[instance])); CKEDITOR.instances[instance].document.on("change", updateText(CKEDITOR.instances[instance])); } } }); } }; })(jQuery, Drupal, Drupal.debounce, (typeof CKEDITOR === 'undefined') ? undefined : CKEDITOR);